package leetcode_周赛._2021._202106._20210606;

/**
 * @author yzh
 * @version 1.0
 * @date 2021/6/6 10:32
 * 判断矩阵经轮转后是否一致
 * 旋转 90 度，就是先转置，然后每行翻转
 * 暴力解法，把所有的旋转都算出来
 */
public class _5776 {

    public boolean findRotation(int[][] mat, int[][] target) {
        int m = mat.length, n = mat[0].length;
        for (int i = 0; i < 4; i++) {
            xuanzhuan(mat, m, n);
            if (compare(mat, target, m, n)) return true;
        }
        return false;
    }
    public boolean compare(int[][] mat, int[][] target, int m, int n) {
        boolean flag = true;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (mat[i][j] != target[i][j]) flag = false;
            }
        }
        if (flag) return true;
        return false;
    }
    public void xuanzhuan(int[][] mat, int m, int n) {
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < i; j++) {
                int tmp = mat[j][i];
                mat[j][i] = mat[i][j];
                mat[i][j] = tmp;
            }
        }
        for (int i = 0; i < m; i++) {
            for (int j = 0 ; j < (n / 2); j++) {
                int tmp = mat[i][n - 1 - j];
                mat[i][n - 1 - j] = mat[i][j];
                mat[i][j] = tmp;
            }
        }
    }

}
